package io.github.uicdb.et.compat;

import io.github.uicdb.et.ElementalTheory;
import io.github.uicdb.et.ModRecipes;
import io.github.uicdb.et.recipe.ExtractRecipe;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import org.jetbrains.annotations.NotNull;

import java.lang.annotation.Annotation;
@JeiPlugin
public class JEICompat implements IModPlugin {

    @Override
    public @NotNull ResourceLocation getPluginUid() {
        return ResourceLocation.fromNamespaceAndPath(ElementalTheory.MODID,"jei");
    }

    @Override
    public void registerCategories(IRecipeCategoryRegistration registration) {
        registration.addRecipeCategories(new ExtractRecipeCategory(registration.getJeiHelpers().getGuiHelper()));
    }

    @Override
    public void registerRecipes(@NotNull IRecipeRegistration registration) {
        if(Minecraft.getInstance().level != null) {
            RecipeManager rm = Minecraft.getInstance().level.getRecipeManager();
            var recipe = rm.getAllRecipesFor(ExtractRecipe.TYPE).stream().map(RecipeHolder::value).toList();
            registration.addRecipes(ExtractRecipeCategory.RECIPE_TYPE, recipe);
        }
    }
}
